<?php
$this->breadcrumbs=array(
	Yii::t('base','Customs')=>array('admin'),
	Yii::t('base','Manage'),
);

$this->menu=array(
	array('label'=>'List Custom', 'url'=>array('index')),
	array('label'=>'Create Custom', 'url'=>array('create')),
);

Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
	$('.search-form').toggle();
	return false;
});
$('.search-form form').submit(function(){
	$.fn.yiiGridView.update('custom-grid', {
		data: $(this).serialize()
	});
	return false;
});
");

?>

<h1><?php echo Yii::t('base','Manage Customs');?></h1>

<?php 
echo Yii::t('base','<p>
You may optionally enter a comparison operator (<b>&lt;</b>, <b>&lt;=</b>, <b>&gt;</b>, <b>&gt;=</b>, <b>&lt;&gt;</b>
or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done.
</p>');
?>

<?php echo CHtml::link(Yii::t('base','Advanced Search'),'#',array('class'=>'search-button')); ?>
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
	'model'=>$model,
)); ?>
</div><!-- search-form -->
<?php if(yii::app()->user->level==6 || yii::app()->user->level==7 || yii::app()->user->level==5){?>
<a class="btn btn-small create" title="创建客户" href="<?php echo Yii::app()->request->baseUrl; ?>/custom/create">创建客户</a>
<?php }?>
<?php $this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'custom-grid',
	'dataProvider'=>$model->search3($results),
	'itemsCssClass'=>'responsive table table-striped table-bordered',
	'pager'=>array('class'=>'CLinkPager','hiddenPageCssClass'=>'','firstPageCssClass'=>'first paginate_button','htmlOptions'=>array('class'=>'dataTables_paginate paging_full_numbers"'),'header'=>""),
	'pagerCssClass'=>'pagination',
	'cssFile'=>false,
	'template'=>'{items}{summary}{pager}',
	'columns'=>array(
		'custom_surname',
		'custom_name',
		array('name'=>'user_id','value'=>'Custom::model()->getUserName($data->user_id)'),	
		array('name'=>'equipment_number'),
		array('name'=>'package_id','value'=>'Custom::model()->getPackageName($data->package_id)'),
		array('name'=>'custom_id','value'=>'Custom::model()->deposit($data->user_id)'),
		array('name'=>'reback_time','visible'=>(Yii::app()->request->getParam("isreback")==0)),
		array('name'=>'reback_address','visible'=>(Yii::app()->request->getParam("isreback")==0)),
		array('name'=>'time','visible'=>(Yii::app()->request->getParam("isreback")==1)),
		array('name'=>'address','visible'=>(Yii::app()->request->getParam("isreback")==1)),
		array('name'=>'sale_id','value'=>'User::model()->findByPk($data->sale_id)->user_name'),
		array('name'=>'sale_address'),
		array('name'=>'access_id','value'=>'User::model()->findByPk($data->access_id)->user_name','visible'=>(Yii::app()->request->getParam("isreback")==1)),
		array(
			'class'=>'CButtonColumn',
			'header'=>Yii::t('base','Operate'),
			'updateButtonImageUrl'=>array('class'=>'gicon-edit'),
			'updateButtonOptions'=>array('class'=>'btn btn-small'),
			'viewButtonImageUrl'=>array('class'=>'gicon-edit'),
			'viewButtonOptions'=>array('class'=>'btn btn-small'),
			'deleteButtonImageUrl'=>array('class'=>'gicon-edit'),
			'deleteButtonOptions'=>array('class'=>'btn btn-inverse btn-small'),
//			'template'=>'{view}{update}{delete}{recharge}{Reback equipment}',
			'template'=>'{view}{update}{recharge}{Reback equipment}{update agent custom}',
			'buttons'=>array(
				'recharge'=>array(
				'label'=>Yii::t('base','Recharge'),
				'url'=>'Yii::app()->createUrl("AgentRecharge/create",array("user_id"=>$data->user_id,"custom_id"=>$data->custom_id,"flag"=>"3G","tag"=>1))',
				'options'=>array('class'=>'btn btn-small'),
				'visible'=>'yii::app()->user->level==1'
				),
					'Reback equipment'=>array(
							'label'=>Yii::t('base','Reback equipment'),
							'url'=>'Yii::app()->createUrl("custom/reback",array("user_id"=>$data->user_id,"custom_id"=>$data->custom_id))',
							'options'=>array('class'=>'btn btn-small'),
							'visible'=>'yii::app()->user->level==6 && Custom::model()->isjudge($data->user_id)!=0'
					),
					'update'=>array(
							'label'=>Yii::t('base','To Saled Customer'),
							'url'=>'Yii::app()->createUrl("custom/update",array("id"=>$data->custom_id))',
							'options'=>array('class'=>'btn btn-small'),
							'visible'=>'(yii::app()->request->getParam(isreback)==2 && yii::app()->user->level==1) || (yii::app()->request->getParam(isreback)==2 && yii::app()->user->level==6)'
					),
					'update agent custom'=>array(
							'label'=>Yii::t('base','To Saled Customer'),
							'url'=>'Yii::app()->createUrl("custom/agentupdate",array("id"=>$data->custom_id))',
							'options'=>array('class'=>'btn btn-small'),
							'visible'=>'(yii::app()->request->getParam(isreback)==2 && yii::app()->user->level==4) || (yii::app()->request->getParam(isreback)==2 && yii::app()->user->level==7)'
					),
					
			)
		),
	),
)); ?>
